//
//  SpecialPlayVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/1/2.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "SpecialPlayVC.h"
#import "SDCycleScrollView.h"
#import "MyPlayProgressView.h"
#import "SpecialInforCell.h"
#import "SpecialIntroduceCell.h"
#import "UserCommentsCell.h"
#import "GuiderIconView.h"
#import "IGAvPlayerManager.h"
#import "SpecialAudioListView.h"
#import "SectionTitleHeaderView.h"
#import "GuiderDetailVC.h"
#import <IQTextView.h>
#import <IQKeyboardManager.h>
#import "RewardView.h"
#import "ChargeMoneyVC.h"
#import "UserCommentsVC.h"
#import "RewardRecordVC.h"
#import "ProgressBtn.h"
@interface SpecialPlayVC ()<UITableViewDelegate,UITableViewDataSource,MyPlayProgressViewDelegate,SpecialAudioListViewDelegate,IGAvPlayerManagerDelegate,RewardViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *headView;

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet SDCycleScrollView *cycleImageView;


@property (weak, nonatomic) IBOutlet MyPlayProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *downloadProgressLabel;

@property (weak, nonatomic) IBOutlet UIButton *playBtn;


@property (weak, nonatomic) IBOutlet UIButton *speedBtn;

@property (weak, nonatomic) IBOutlet UILabel *totalLabel;

@property (weak, nonatomic) IBOutlet UILabel *currentTimeLabel;

@property (weak, nonatomic) IBOutlet UIButton *guiderBtn;
@property (weak, nonatomic) IBOutlet UILabel *guiderNameLabel;

@property (weak, nonatomic) IBOutlet UIView *guiderView;

@property (weak, nonatomic) IBOutlet GuiderIconView *guiderHeaderView;


//---功能按钮
@property (weak, nonatomic) IBOutlet UIView *commentView;
@property (weak, nonatomic) IBOutlet UILabel *commentCountLabel;

@property (weak, nonatomic) IBOutlet UIView *payView;



@property (weak, nonatomic) IBOutlet UIButton *writeCommentBtn;

@property (weak, nonatomic) IBOutlet UILabel *commentLabel;
@property (weak, nonatomic) IBOutlet IQTextView *writeCommtesTextView;


@property (weak, nonatomic) IBOutlet UILabel *charCountLable;

@property (weak, nonatomic) IBOutlet UIButton *submitBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *commentViewBottomSpac;

@property (weak, nonatomic) IBOutlet UIView *writeCommentsView;

@property (weak, nonatomic) IBOutlet UILabel *rewardDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *commentDesLabel;
@property (nonatomic, strong)RewardView * rewardView;

@property (nonatomic, strong)SpecialAudioListView * audioListView;

@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)IGAvPlayerManager * manager;
@property (nonatomic, strong)NSArray <ScenicPoint *>* dataSource;
@property (nonatomic, copy)NSString * playPath;

@property (nonatomic, assign)CGFloat currentSpeed;

@end

@implementation SpecialPlayVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setup];
    [self setNotification];
    [self loadDataSource];
}

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    [IQKeyboardManager sharedManager].enable = NO;
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    self.rt_disableInteractivePop = NO;
    [IQKeyboardManager sharedManager].enable = YES;
}

- (void)setNotification {
    
    self.commentViewBottomSpac.constant = 0;
    self.writeCommentsView.hidden = YES;
    [self.writeCommentBtn setTitle:MYLocalizedString(@"SITEPLAY_COMMENT_PLACEHOLDER", nil) forState:UIControlStateNormal];
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    //注册键盘弹出通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    //注册键盘隐藏通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    
    //播放状态改变通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PlayBarchangePlayStateWith:) name:kIGAvPlayerManagerState object:nil];
}
- (void)setup {
    
    [self.submitBtn setTitle:MYLocalizedString(@"PUBLIC_CONFIRM", nil) forState:UIControlStateNormal];
    
    self.commentLabel.text = MYLocalizedString(@"SITEPLAY_WRITE_COMMENT", nil);
    
    self.rewardDesLabel.text = MYLocalizedString(@"COIN_REWARD", nil);
    self.commentDesLabel.text = MYLocalizedString(@"SITEPLAY_COMMENT", nil);
    NSInteger seconds = self.currentScenicPoint.duration / 1000 % 60;
    NSInteger minutes = (self.currentScenicPoint.duration / 1000 / 60);
    self.totalLabel.text = [NSString stringWithFormat:@"%02d:%02d", (int)minutes, (int)seconds];
    
    self.currentTimeLabel.text = @"00:00";
    
    self.guiderView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    self.writeCommtesTextView.placeholder = MYLocalizedString(@"SITEPLAY_COMMENT_TIPS", nil);
    self.writeCommtesTextView.textColor = kContentColor;

    self.progressView.delegate = self;
    [self setAutoRowHeight:self.tableView];
    [self closeAutomaticallyAdjustsScrollViewInsets:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"UserCommentsCell" bundle:nil] forCellReuseIdentifier:@"UserCommentsCell"];
    
    [self.tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"UITableViewHeaderFooterView"];
    
    [self.tableView registerClass:[SectionTitleHeaderView class] forHeaderFooterViewReuseIdentifier:@"SectionTitleHeaderView"];
    
    [self.commentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goComments)]];
    
    [self.payView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goReward)]];
    
}


- (void)loadDataSource {
    
//    self.title = self.lineModel.linename;
    self.commentCountLabel.text = self.lineModel.commentnum;
    
    if (self.lineModel.records.count > 0) {
        self.dataSource = self.lineModel.records;
        self.manager.lineModel = self.lineModel;
        self.manager.dataSource = self.dataSource;
        self.manager.playType = PlaySpecial;
    }
    self.guiderHeaderView.headerImageName = self.lineModel.guide.headimg;
    self.guiderHeaderView.vip = self.lineModel.guide.vip;
    
    self.guiderNameLabel.text = self.lineModel.guide.realname;
    
    self.manager.delegate = self;
    self.cycleImageView.imageURLStringsGroup = self.currentScenicPoint.pictureArray;
    self.title = self.currentScenicPoint.spotname;
    if (self.manager.isPlay && [self.manager.currentURL isEqualToString:self.currentScenicPoint.playpath]) {
        
        self.playBtn.selected = YES;
        self.progressView.trackValue = 1.0;
        self.progressView.value = self.manager.progress/self.manager.totaltime;
    }else{
        
        [self.manager resetPlaySpeed];
        [self playMusicWithIndex:[self.dataSource indexOfObject:self.currentScenicPoint]];
    }
  
    [self setupSpeed];
    [self.tableView reloadData];
    
}


- (void)playMusicWithIndex:(NSInteger)index {
    
    ScenicPoint *point = self.lineModel.records[index];
     [self.manager playMusic:index withIsPlay:YES];
     self.currentIndex = index;
     self.currentScenicPoint = point;
    self.cycleImageView.imageURLStringsGroup = point.pictureArray;
    self.title = point.spotname;
    [self.tableView reloadData];
}
- (RewardView *)rewardView {
    
    if (!_rewardView) {
        
        _rewardView = [[RewardView alloc] initWithFrame:CGRectMake(0, (kScreenHeight - RewardH), kScreenWidth, RewardH)];
        _rewardView.delegate = self;
    }
    
    return _rewardView;
}
- (IGAvPlayerManager *)manager {
    
    if (!_manager) {
        
        _manager = [IGAvPlayerManager shareManeger];
    }
    
    return _manager;
}

- (SpecialAudioListView *)audioListView {
    
    if (!_audioListView) {
        _audioListView = [[SpecialAudioListView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight/2 + 53)];
        _audioListView.delegate = self;
        
//        @weakify(self);
//        [self.sl_popupController setWillDismiss:^(SnailPopupController * _Nonnull popupController) {
////            @strongify(self)
//            //[self setDownloadProgress:nil];
//        }];
    }
    
    return _audioListView;
}

-(UIView *)bgView {
    
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:self.view.frame];
        _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    }
    
    return _bgView;
}
-(void)selectPointIndex:(NSInteger)index {
    
    ScenicPoint * point =  self.dataSource[index];
    
    self.cycleImageView.imageURLStringsGroup = point.pictureArray;
    self.title = point.spotname;
    [self.manager playMusic:index withIsPlay:YES];
}

- (IBAction)writeCommentBtnClicked:(id)sender {
    
    if (![IGUtil hasLoginOrPresentLogin]) {
        return;
    }
    
    [self.writeCommtesTextView becomeFirstResponder];
    
}
- (void)goReward {
    
    if (![IGUtil hasLoginOrPresentLogin]) {
        
        return;
    }
    
    self.sl_popupController.layoutType = PopupLayoutTypeBottom;
    [self.sl_popupController presentContentView:self.rewardView];
    
    
    self.rewardView.lineid = self.lineModel.lineid;
}


- (void)goComments {
    
    UserCommentsVC * userCommentsVC = [[UserCommentsVC alloc] init];
    
    NSLog(@"lineid %@",self.lineModel.lineid);
    
    userCommentsVC.lineID = self.lineModel.unionid;
    userCommentsVC.type = 1;
    
    [self.navigationController pushViewController:userCommentsVC animated:YES];
    
}

- (IBAction)submitBtnClicked:(id)sender {
    
    NSString *comment = self.writeCommtesTextView.text;
    if ([IGUtil isStringLenght0:comment]) {
        [IGUtil showToast:MYLocalizedString(@"COMMENT_NULL_TIP", nil)];
        
        return;
    }
    
    @weakify(self);
    [NetAPIManager evaluate:self.lineModel.unionid isLine:NO score:nil comment:comment Block:^(NSString *result, NSError *error) {
        @strongify(self);
        if (!error) {
            [IGUtil showToast:MYLocalizedString(@"PUBLIC_COMMIT_SUCCESS", nil)];
            
            Comment *cm = [Comment new];
            cm.headimg = [UserManager sharedManager].user.headimg;
            cm.realname = [UserManager sharedManager].user.realname;
            cm.touristid = [UserManager sharedManager].user.uid;
            cm.comment = comment;
            cm.time = [NSDate date];
            
            self.lineModel.commentnum = @(self.lineModel.commentnum.integerValue +1).stringValue;
            NSMutableArray *commentArray = [NSMutableArray arrayWithArray:self.lineModel.comments];
            [commentArray insertObject:cm atIndex:0];
            
            self.lineModel.comments = commentArray;
            [self loadDataSource];
            
            self.writeCommtesTextView.text = @"";
            
            [self.writeCommtesTextView resignFirstResponder];
            
        }
    }];
}

- (IBAction)goGuiderDetail:(id)sender {
    
    GuiderDetailVC * guiderDetailVC = [[GuiderDetailVC alloc] init];
    guiderDetailVC.guiderID = self.lineModel.guideid;
    
    [self.navigationController pushViewController:guiderDetailVC animated:YES];
}

- (IBAction)showSpecailList:(id)sender {
    
    
    self.sl_popupController.layoutType = PopupLayoutTypeBottom;
    [self.sl_popupController presentContentView:self.audioListView];
    self.audioListView.special = self.lineModel;
    self.audioListView.superVC = self;
}

- (IBAction)preBtnClicked:(id)sender {
    
    [[IGAvPlayerManager shareManeger] previous];
}

- (IBAction)nextBtnClicked:(id)sender {
    [[IGAvPlayerManager shareManeger] next];
}

- (IBAction)playBtnClicked:(id)sender {
    
    if ([IGAvPlayerManager shareManeger].isPlay) {
        [self.manager pause];
        
    }else {
        
        [self.manager play];
    }
    
}

- (void)setupSpeed{
    
    if ([IGAvPlayerManager shareManeger].isPlay) {
        self.currentSpeed = [IGAvPlayerManager shareManeger].playSpeed;
    }else{
        self.currentSpeed = 1.0;
    }
    NSString *str = @"speed1.0x";
    if (self.currentSpeed == 1.25) {
        str = @"speed1.25x";
    }else if(self.currentSpeed == 1.5){
        str = @"speed1.5x";
    }
    [_speedBtn setImage:[UIImage imageNamed:str] forState:UIControlStateNormal];
}

- (IBAction)changeSpeed:(UIButton *)sender {
    
    if (self.currentSpeed == 1.0) {
        [_speedBtn setImage:[UIImage imageNamed:@"speed1.25x"] forState:UIControlStateNormal];
        self.currentSpeed = 1.25;
        self.manager.playSpeed = 1.25;
        
    }else if(self.currentSpeed == 1.25){
        
        [_speedBtn setImage:[UIImage imageNamed:@"speed1.5x"] forState:UIControlStateNormal];
        self.currentSpeed = 1.5;
        self.manager.playSpeed = 1.5;
    }else if(self.currentSpeed == 1.5){
        [_speedBtn setImage:[UIImage imageNamed:@"speed1.0x"] forState:UIControlStateNormal];
        self.currentSpeed = 1.0;
        self.manager.playSpeed = 1.0;
    }
}


//- (IBAction)downloadBtnClicked:(id)sender {
//
//    if (![IGUtil hasLoginOrPresentLogin]) {
//
//        [self.superVC.sl_popupController dismiss];
//        return;
//    }
//
//    MCDownloadReceipt *receipt = [[DownloadManager sharedManager] downloadReceiptForURLString:self.currentScenicPoint.playpath];
//
//    if (receipt.state == MCDownloadStateCompleted) {
//        return;
//    }
//
//    [[DownloadManager sharedManager] addDownloadWithLineModel:self.lineModel point:self.currentScenicPoint];
//}

#pragma mark  -- RewardViewDelegate

- (void)recharge {
    
    ChargeMoneyVC * moneyVC = [IGUtil loadViewController:@"ChargeMoneyVC" storyboard:@"Account"];
    
    [self.sl_popupController dismiss];
    [self.navigationController pushViewController:moneyVC animated:YES];
}

- (void)rewardWithModel:(RewardModel *)model {
    
    [NetAPIManager rewardWithLineid:self.lineModel.lineid coin:model.amount block:^(NSString *result, NSError *error) {
        
        if (!error) {
            [[NSNotificationCenter defaultCenter] postNotificationName:kReloadUserDataNotif object:nil];
            [IGUtil showToast:MYLocalizedString(@"REWARD_SUCCESS", nil)];
            [self.sl_popupController dismiss];
        }
    }];
}

- (void)showRewardRecord {
    
    RewardRecordVC *recordVC = [RewardRecordVC new];
    recordVC.unionid = self.lineModel.unionid;
    [self.sl_popupController dismiss];
    
    [self.navigationController pushViewController:recordVC animated:YES];
}

#pragma mark  -- playAudio

- (void)changeScenicPointTo:(NSInteger)index {
    
    self.currentScenicPoint= self.dataSource[index];
    
    self.cycleImageView.imageURLStringsGroup = self.currentScenicPoint.pictureArray;
    self.title = self.currentScenicPoint.spotname;
    [self.tableView reloadData];
}



#pragma mark   - IGAvPlayerManagerDelegate

- (void)updateBufferProgress:(NSTimeInterval)progress{
    
    self.progressView.trackValue = progress;
}

- (void)updateProgressWith:(CGFloat)value{
    
//    if (![[IGAvPlayerManager shareManeger].currentURL isEqualToString:self.currentScenicPoint.playpath]) {
//        return;
//    }
    [self.progressView setValue:value];
    
    self.totalLabel.text = self.manager.durantion;
    self.currentTimeLabel.text = self.manager.currentTime;
}

- (void)PlayBarchangePlayStateWith:(NSNotification *)notif
{
    NSInteger state = [notif.userInfo[kIGAvPlayerManagerState] integerValue];
    
   // NSString  * url = notif.userInfo[kCurrentPlayURL];
//    if (![url isEqualToString:self.currentScenicPoint.playpath]) {
//        return;
//    }
    switch (state) {
        case AVPlayerPlayStatePreparing:
        case AVPlayerPlayStateBeigin:{
            
            self.playBtn.selected = YES;
        }
            break;
        case AVPlayerPlayStatePlaying:
        {
            self.playBtn.selected = YES;
            
        }
            break;
        case AVPlayerPlayStatePause: {
            self.playBtn.selected = NO;
            
        }
            break;
        case AVPlayerPlayStateEnd:
        {
            //self.totalLabel.text = @"00:00";
            self.playBtn.selected = NO;
        }
            break;
        case AVPlayerPlayStateNotPlay:
            
        {
            self.totalLabel.text = @"";
            self.currentTimeLabel.text = @"";
            self.progressView.value = 0.;
            self.playBtn.selected = NO;
        }
            break;
        case AVPlayerPlayStateseekToZeroBeforePlay:
        {
            self.progressView.value = 0.;
            
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark   - MyPlayProgressViewDelegate


- (void)beiginSliderScrubbing {
    
}


- (void)endSliderScrubbing {
    [self.manager musicSeekToTime:self.progressView.value];
}


- (void)sliderScrubbing {
    
    self.currentTimeLabel.text = [_manager timeFormatted:self.progressView.value * _manager.totaltime];
    
    IGLog(@"----%f",self.progressView.value);
}



#pragma mark -SpecialAudioListViewDelegate

- (void)selectIndex:(NSInteger)index {
    
    [self.sl_popupController dismiss];
    
    ScenicPoint * point = self.lineModel.records[index];
    if ([point.ID isEqualToString:self.currentScenicPoint.ID]) {
        return;
    }
    [self playMusicWithIndex:index];
}



//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    
//    CGFloat yOffset = self.tableView.contentOffset.y;
//    CGFloat H = kScreenWidth;
//    
//    if (yOffset < H - kNavigationBarHeight  ) {
//        
//        CGFloat aplha = yOffset /(H -kNavigationBarHeight);
//        
//        self.barBGAlpha = aplha;
//    }else {
//        self.barBGAlpha = 1;
//    }
//    
//    if (self.barBGAlpha > 0.5) {
//        self.customBarStyle = UIStatusBarStyleDefault;
//    } else {
//        self.customBarStyle = UIStatusBarStyleLightContent;
//    }
//}
#pragma mark -- UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    if (self.lineModel.comments.count > 0) {
        return 2;
    }
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        
        return 2;
    }
    
    return self.lineModel.comments.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
            SpecialInforCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SpecialInforCell"];
            cell.model = self.lineModel;
            
            return cell;
        } else {
            
            SpecialIntroduceCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SpecialIntroduceCell"];
            
            cell.contentLabel.text = self.currentScenicPoint.linedesc;
            
            return cell;
        }
    }
    
    Comment *comment = self.lineModel.comments[indexPath.row];
    
    UserCommentsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"UserCommentsCell"];
    [cell configDataWith:comment];
    cell.type = 1;
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    if (section == 1) {
        SectionTitleHeaderView * headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"SectionTitleHeaderView"];
        headerView.contentView.backgroundColor = [UIColor whiteColor];
        headerView.SectionTitle = MYLocalizedString(@"SITEPLAY_USER_COMMENT", nil);
        
        return headerView;
    }
    
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 1) {
        
        return 55;
    }
    return 9;
}


#pragma mark   键盘弹出

- (void)keyboardWillShow:(NSNotification *)note {
    
    NSDictionary *info = [note userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    
    [self.view insertSubview:self.bgView belowSubview:self.writeCommentsView];
    self.commentViewBottomSpac.constant = keyboardSize.height;
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
    self.writeCommentsView.hidden = NO;
}

- (void)keyboardWillHide:(NSNotification *)note {
    
    self.commentViewBottomSpac.constant = 0;
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [self.bgView removeFromSuperview];
        
    }];
    self.writeCommentsView.hidden = YES;
}



#define MAX_STARWORDS_LENGTH 200

- (void)textViewDidChange:(UITextView *)textView {
    
    NSString * string  =  textView.text;
    
    //获取高亮部分
    
    UITextRange * seletedRange = [textView markedTextRange];
    
    UITextPosition * position = [textView positionFromPosition:seletedRange.start offset:0];
    
    // 没有高亮选择的字， 就对其进行字数统计和限制
    
    if (!position) {
        
        if (string.length > MAX_STARWORDS_LENGTH) {
            
            NSRange rangeIndex = [string rangeOfComposedCharacterSequenceAtIndex:MAX_STARWORDS_LENGTH];
            if (rangeIndex.length == 1) {
                
                textView.text = [string substringToIndex:MAX_STARWORDS_LENGTH];
            }else {
                
                NSRange rangeRange = [string rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, MAX_STARWORDS_LENGTH)];
                
                textView.text = [string substringWithRange:rangeRange];
            }
        }
    }
    int length =(int)(MAX_STARWORDS_LENGTH - textView.text.length);
    
    if (length >=0) {
        
        self.charCountLable.text = @(MAX_STARWORDS_LENGTH - textView.text.length).stringValue;
    }
    
}

//- (void)setDownloadState:(MCDownloadState)downloadState {
//
//
//    dispatch_main_async_safe( ^{
//
//        switch (downloadState) {
//            case MCDownloadStateDownloading:
//            {
//                [self.downloadBtn setImage:[UIImage imageNamed:@"continue"] forState:UIControlStateNormal];
//                self.downloadProgressLabel.text = @"";
//                self.downloadProgressLabel.hidden = NO;
//                self.downloadBtn.userInteractionEnabled = YES;
//            }
//                break;
//            case MCDownloadStateCompleted:
//            {
//                [self.downloadBtn setImage:[UIImage imageNamed:@"complete"] forState:UIControlStateNormal];
//                self.downloadProgressLabel.text = @"";
//                self.downloadProgressLabel.hidden = YES;
//                self.downloadBtn.userInteractionEnabled = NO;
//                [self.downloadBtn setProgress:0.f];
//            }
//                break;
//            case MCDownloadStateFailed:
//            {
//                [self.downloadBtn setImage:[UIImage imageNamed:@"retry"] forState:UIControlStateNormal];
//                [self.downloadBtn setProgress:0.f];
//                self.downloadProgressLabel.hidden = YES;
//                self.downloadBtn.userInteractionEnabled = YES;
//            }
//                break;
//            default:{
//                [self.downloadBtn setImage:[UIImage imageNamed:@"download"] forState:UIControlStateNormal];
//                [self.downloadBtn setProgress:0.f];
//                self.downloadProgressLabel.text = @"";
//                self.downloadProgressLabel.hidden = YES;
//                self.downloadBtn.userInteractionEnabled = YES;
//            }
//                break;
//        }
//    });
//
//
//}

//- (void)setDownloadProgress:(NSNotification *)notification {
//
//    if (notification && ![notification.object isKindOfClass:NSClassFromString(@"MCDownloadOperation")]) {
//        return;
//    }
//
//
//    MCDownloadReceipt *receipt1 = [notification.object valueForKey:@"receipt"];
//
//    if (receipt1 && [receipt1 isKindOfClass:[MCDownloadReceipt class]] && ![receipt1.url isEqualToString:self.currentScenicPoint.playpath]) {
//
//        return;
//    }
//
//    [self changeDownloadSateWithTheScenicPoint:self.self.currentScenicPoint];
//
//}
//
//
//- (void)changeDownloadSateWithTheScenicPoint:(ScenicPoint *)point {
//
//    MCDownloadReceipt *receipt = [[DownloadManager sharedManager] downloadReceiptForURLString:point.playpath];
//
//    @weakify(self);
//    receipt.downloaderProgressBlock = ^(NSInteger receivedSize, NSInteger expectedSize, NSInteger speed, NSURL * _Nullable targetURL) {
//        @strongify(self);
//
//        if (![targetURL.absoluteString isEqualToString:point.playpath]) {
//
//            return;
//        }
//
//        CGFloat progress = receivedSize * 1.0f / expectedSize;
//
//        if (progress >= 1) {
//            progress = 1;
//        } else if (progress < 0) {
//            progress = 0;
//        }
//        if (progress >=0 && progress <=1) {
//
//            self.downloadProgressLabel.text =[NSString stringWithFormat:@"%.f%%",progress * 100];
//
//            if (progress == 1) {
//                [self setDownloadState:MCDownloadStateCompleted];
//            }
//        }
//    };
//
//    receipt.downloaderCompletedBlock = ^(MCDownloadReceipt *receipt, NSError * _Nullable error, BOOL finished) {
//
//        if (![receipt.url isEqualToString:point.playpath]) {
//
//            return;
//        }
//
//        if (error) {
//            [self setDownloadState:MCDownloadStateFailed];
//
//        } else {
//
//            [self setDownloadState:MCDownloadStateCompleted];
//        }
//    };
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */



@end

